package com.atguigu.gulimall.order.web;

import com.alipay.api.AlipayApiException;

import com.atguigu.gulimall.order.pay.AlipayTemplate;
import com.atguigu.gulimall.order.pay.PayVo;
import com.atguigu.gulimall.order.service.OrderService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * @Author 小坏
 * @Date 2021/2/23 20:02
 * @Version 1.0
 * @program: 父工程 gulimall 万物起源之地
 */

@Controller
public class PayWebController {

    @Autowired
    AlipayTemplate alipayTemplate;


    @Autowired
    OrderService orderService;

    /**
     * 将支付页让浏览器显示
     * 支付成功以后、我们要调到用户的订单列表页
     *
     * @param orderSn
     * @return
     * @throws AlipayApiException
     */
    @ResponseBody
    @GetMapping(value = "/payOrder", produces = "text/html")
    public String payOrder(@RequestParam("orderSn") String orderSn) throws AlipayApiException {
//        PayVo payVo = new PayVo ();
//        String pay = alipayTemplate.pay (payVo);
        //封装支付参数
        PayVo payVo = orderService.getOrderPay (orderSn);

        //提交支付
        String pay = alipayTemplate.pay (payVo);
        System.out.println (pay);
        return pay;
    }


}
